package com.gxa.modules.pc.sys.homepage.service.impl;

import com.gxa.common.utils.Result;
import com.gxa.modules.pc.sys.homepage.dto.*;
import com.gxa.modules.pc.sys.homepage.mapper.HomePageMapper;
import com.gxa.modules.pc.sys.homepage.service.HomePageService;
import org.apache.ibatis.binding.BindingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName HomePageServiceImpl
 * @Description
 * @Author Mr.YUAN
 * @Date 2022/11/17 13:09
 */

@Service
public class HomePageServiceImpl implements HomePageService {

    @Autowired
    private HomePageMapper homePageMapper;
    @Override
    public Result queryHomePage() {
        HashMap<String, Object> map = new HashMap<>();
        //数据总浏览
        int totalAppoint = homePageMapper.getHsAppoint()+homePageMapper.getTjAppoint()+homePageMapper.getRegister();
        DataView dataView = new DataView(totalAppoint,homePageMapper.getRegister(),homePageMapper.getRecharge(),homePageMapper.getExpense(),homePageMapper.getBinding());
//        try {
//            dataView.setAppoint(totalAppoint)
//                    .setRegister(homePageMapper.getRegister())
//                    .setRecharge(homePageMapper.getRecharge())
//                    .setExpend(homePageMapper.getExpense())
//                    .setBinding(homePageMapper.getBinding());
//        } catch (BindingException e) {
//            e.printStackTrace();
//            throw new BindingException("今天还没有数据");
//        }

        //近七日预约挂号情况
        List<AppointDetail> appointDetails = homePageMapper.queryAppointDetail();
        //充值趋势
        List<RechargeDetail> rechargeDetails = homePageMapper.queryRechargeDetail();
        //实时挂号
        List<RealTimeRegister> realTimeRegisters = homePageMapper.queryRealTimeRegister();
        //热门科室
        List<HostDepartment> hostDepartments = homePageMapper.queryHostDepartment();
        //热门医生
        List<HostDoctor> hostDoctors = homePageMapper.queryHostDoctor();
        map.put("dataView", dataView);
        map.put("appointDetails", appointDetails);
        map.put("rechargeDetails", rechargeDetails);
        map.put("realTimeRegisters", realTimeRegisters);
        map.put("hostDepartments", hostDepartments);
        map.put("hostDoctors", hostDoctors);
        return new Result().ok(map);
    }
}